<!--收件箱-->
<div class="dataTables_filter " id="searchDiv" style="display: none">
    <!--查询条件-->
    <!-- <div class="has-feedback">
         <input type="text" class="form-control input-sm" placeholder="Search Mail">
         <span class="glyphicon glyphicon-search form-control-feedback"></span>
     </div>-->
    <input type="hidden" name="receiveUserID" value="${user.id}">
    <div class="has-feedback form-group">
        <input type="search" placeholder="请输入标题" title="主题" name="message.sendSubject"
               class="form-control input-sm" id="sendSubject" operator="like" likeOption="true">
        <span class="glyphicon glyphicon-search form-control-feedback"></span>
    </div>
    <button type="button" class="btn btn-primary btn-sm" data-callback="enableOrDisableButtons()" data-btn-type="search"
            title="查询"><i class="fa fa-refresh"></i></button>
    <div class="btn-group">
        <button type="button" class="btn btn-default btn-sm" disabled data-btn-type="delete" title="放入回收站"><i
                class="fa fa-trash-o"></i></button>
        <button type="button" class="btn btn-default btn-sm" disabled data-btn-type="reply" title="回复邮件"><i
                class="fa fa-reply"></i></button>
        <button type="button" class="btn btn-default btn-sm" disabled data-btn-type="share" title="转发邮件"><i
                class="fa fa-share"></i></button>

    </div>
    <div class="btn-group">
        <button type="button" class="btn btn-default btn-sm" disabled data-btn-type="readNo" title="标记为未读"><i
                class="fa fa-flag-o"></i></button>
        <button type="button" class="btn btn-default btn-sm" disabled data-btn-type="readYes" title="标记为已读"><i
                class="fa fa-flag text-yellow"></i></button>
    </div>
</div>
<div class="box-body">
    <table id="message_inbox_table" style="border-top:1px solid #f4f4f4;"
           class="table table-border table-striped table-hover">
    </table>
</div>
<script>
    var inboxTable;
    $(function () {
        var config = {
            rowClick: function (row, isSelected) {
                enableOrDisableButtons();
            }
        }
        inboxTable = new CommonTable("message_inbox_table", "message_inbox", "searchDiv", config);

        $("[data-btn-type]").click(function () {
            var btnType = $(this).data("btn-type");
            var rId = inboxTable.getSelectedRowId();
            var rowData = inboxTable.getSelectedRowData();
            switch (btnType) {
                case "delete":
                    modals.confirm("是否将该消息放入回收站?", function () {
                        ajaxPost(basePath + "/message/receiver/trash/" + rId, null, function () {
                            inboxTable.reloadData();
                            updateMsgCount();
                        });
                    });
                    break;
                case "reply":
                    loadPage(basePath+"/message/reply/"+rId,"#contentBody");
                    $(".content-header small").text("回复消息");
                    break;
                case "share":
                    loadPage(basePath+"/message/share/"+rId,"#contentBody");
                    $(".content-header small").text("转发消息");
                    break;
                case "readNo":
                    if (rowData.readYet == 0) {
                        modals.info("该消息当前为未读状态，不可标记为未读");
                        return;
                    }
                    modals.confirm("是否将该消息标记为未读?", function () {
                        ajaxPost(basePath + "/message/receiver/readUpdate/" + rId, null, function () {
                            inboxTable.reloadData();
                        });
                    });
                    break;
                case "readYes":
                    if (rowData.readYet == 1) {
                        modals.info("该消息当前为已读状态，不可标记为已读");
                        return;
                    }
                    modals.confirm("是否把该消息标记为已读?", function () {
                        ajaxPost(basePath + "/message/receiver/readUpdate/" + rId, null, function () {
                            inboxTable.reloadData();
                        });
                    });
                    break;
                default:
                    break;
            }
        })

    });
    //点击标题，阅读邮件
    function readMsg(id) {
        //更新阅读标记和阅读时间
        loadPage(basePath + "/message/receiver/read/" + id, "#contentBody");
        $(".content-header small").text("阅读消息");
    }

    function enableOrDisableButtons() {
        var rowId = inboxTable.getSelectedRowId();
        var btnArr = ["delete", "reply", "share", "readYes", "readNo"];
        if (rowId) {
            $.each(btnArr, function (index, flag) {
                $("[data-btn-type='" + flag + "'").removeAttr("disabled");
            })
        } else {
            $.each(btnArr, function (index, flag) {
                $("[data-btn-type='" + flag + "'").attr("disabled", "disabled");
            })
        }
    }
</script>
